﻿using System;
using System.Collections.Generic;
using System.Linq;
using MockPrjTeam2.Entity;
using MockPrjTeam2.Common;
using System.Data.SqlClient;
using System.Web;

namespace MockPrjTeam2.DAO
{
    public class TownDao
    {
        public List<Town> getAllTown(int id)
        {
            const string getTownQuery = @"SELECT TownId,TownName FROM Town where CountyId = @CountyId";
            var listTown = new List<Town>();
            var sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter { ParameterName = "@CountyId", Value = id };
            using(var helper = new SqlHelper())
            {
                var reader = helper.ExecuteReader(getTownQuery, sqlParameter);
                while (reader.Read())
                {
                    var town = new Town(reader.GetInt32(0), reader.GetString(1));
                    listTown.Add(town); 
                }
            }
            return listTown;
        }
    }
}